<%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib
        uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<%--    <base href="<%=basePath%>">--%>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="description" content="">
    <%-- <base href="<%=basePath%>"> --%>
    <title>备品配件验收指令明细</title>
    <link rel="stylesheet"
          href="<%=basePath%>resourse/weui/lib/weui.min.css">
    <link rel="stylesheet"
          href="<%=basePath%>resourse/weui/css/jquery-weui.min.css">
    <script src="<%=basePath%>resourse/weui/lib/jquery-2.1.4.js"></script>
    <script src="<%=basePath%>resourse/weui/js/jquery-weui.min.js"></script>
</head>
<style>
    .form-value {
        margin-left: 30px;
    }

    .weui-label {
        display: block;
        width: 120px;
        word-wrap: break-word;
        word-break: break-all;
    }

</style>
<script>
    $(function () {
        var partDetailsList = '${partDetails}'

        /* $("[name='parAssessType']").select({
             title: "请选择",
             items: [],
             onClose: function (values) {
                 $('#parAssessTypeCodeTemp').val(values.data.values)
                 $('#parAssessTypeText').val(values.data.titles)
             }
         });
         const assessTypeOptions = getResultOptions('assessType')
         $("[name='parAssessType']").select("update", {items: assessTypeOptions});*/
    })

</script>
<body ontouchstart>
<div class="weui-tab">
    <%--<div class="weui-navbar">
        <a class="weui-navbar__item weui-bar__item--on"> 备品配件验收指令明细</a>
    </div>--%>
    <div class="weui-tab__bd">
        <div id="tab1" class="weui-tab__bd-item weui-tab__bd-item--active">
            <div class="weui-cells weui-cells_form">
                <div class="weui-cells__title">检验批信息</div>
                <%-- parId --%>
                <input type="hidden" value="${partsModel.parId}" id="parId">
                <%-- 接口id --%>
                <input type="hidden" value="${partsModel.interfaceId}" id="interfaceId">
                <%--                工厂CODE--%>
                <input type="hidden" value="${partsModel.parFactory}" id="parFactory">
                <%-- <div class="weui-cell">
                     <div class="weui-cell__hd"><label class="weui-label">工厂：</label></div>
                     <div class="weui-cell__bd">

                         <input class="weui-input form-value" type="text" value="${partsModel.parFactoryDetail}">
                     </div>--%>

            </div>
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">检验批号编号：</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input form-value" type="text" value="${partsModel.parCheckCode}">
                </div>
            </div>
            <%-- <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">检验批来源：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parCheckSourse}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">检验类型：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parCheckType}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">物料编号：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.mmCode}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">物料描述：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.mmDetail}">
                 </div>--%>
            <%-- </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">批次编号：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parCode}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">存储地点：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parAddress}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">组：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parGroup}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">组计数器：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parGroupNum}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">检验开始日期：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parCheckStartDate}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">检验结束日期：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parCheckEndDate}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">用途：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parUse}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">检验批数量：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parCheckNum}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">供应商：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parSupplyCode}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">供应商名称：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parSupplyName}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">采购凭证：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parProof}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">采购凭证的项目编号：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.parProjectNum}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">物料凭证：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.mmProof}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">物料凭证中的项目：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.mmProofProject}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">创建人姓名：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.createName}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">创建时间：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${partsModel.createTime}">
                 </div>
             </div>--%>
        </div>
        <%-- <div class="weui-cells weui-cells_form">
             <div class="weui-cells__title">工序信息</div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">工序编号：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${processModel.procNum}">
                 </div>
             </div>
             <div class="weui-cell">
                 <div class="weui-cell__hd"><label class="weui-label">工序描述：</label></div>
                 <div class="weui-cell__bd">
                     <input class="weui-input form-value" type="text" value="${processModel.procText}">
                 </div>
             </div>
         </div>--%>
        <div class="weui-cells">
            <div class="weui-cells__title">检验特性列表</div>

            <c:forEach items="${partDetails}" var="item" varStatus="status">

                <a class="weui-cell weui-cell_access" href="javascript:void(0)">
                    <input type="hidden" id="procId" value="${item.procId}">
                    <div class="weui-cell__bd">
                        <p style="color: #6692D3" onclick="goItemDetail('${item.deaId}')">${item.deaMainCode} ${item.deaTxt} ${item.deaMain}</p>
                    </div>
                    <div class="weui-cell__ft">
                        <input type="hidden" id="parAssessTypeCodeTemp${status.index}"
                               name="parAssessTypeCodeTemp${status.index}">
                        <input type="hidden" id="parAssessTypeText${status.index}"
                               name="parAssessTypeText${status.index}">
                        <select class="weui-select" name="parAssessType" value="${item.assessCode}"
                                id="${item.deaId}" placeholder="请选择">
                            <option value="">--</option>
                            <option <c:if test="${item.assessCode eq 'A'}"> selected </c:if> value="A">接受</option>
                            <option <c:if test="${item.assessCode  eq 'R'}"> selected </c:if> value="R">拒绝</option>
                        </select><%-- <input class="weui-input form-value" name="parAssessType" style="width: 25%" type="text"
                               id='parAssessType${status.index}' placeholder="请选择">--%>
                    </div>
                </a>
            </c:forEach>
        </div>
    </div>
</div>
<c:if test="${partsModel.status !='1'}">
    <a href="javascript:;" style="width: 96%;margin: 20px auto" onclick="operation()" id="operation"
       class="weui-btn weui-btn_primary">保存</a>
</c:if>
</div>

</body>
<script>
    function operation() {
        $.showLoading();
        let parId = $('#parId').val()
        let procId = $('#procId').val()
// 获取所有name=parAssessType的标签
        var demo = document.getElementsByName("parAssessType")
        for (var int = 0; int < demo.length; int++) {
            // 循环保存检验批的评估信息
            var deaId = demo[int].id
            var accessCode = demo[int].value
            var accessText = demo[int].options[demo[int].selectedIndex].text
            var pd = {
                parId: parId,
                procId: procId,
                deaId: deaId,
                assessCode: accessCode,
                assessText: accessText,
                status:'0'
            }
            $.ajax({
                headers: {
                    token: localStorage.getItem("token")
                },
                async:false,
                type: 'post',
                dataType: 'json',
                url: '<%=basePath%>api/qm/parts/detail/save',
                data: JSON.stringify(pd),
                contentType: "application/json",
                complete: function (XMLHttpRequest) {
                    $.hideLoading();
                    if (XMLHttpRequest.responseJSON.code != 60200) {
                        $.toptip('保存失败', 2000, 'warning');
                    } else {
                        //2.保存成功后
                        $.toptip('保存成功', 2000, 'success');
                    }
                }
            })

        }
        window.location.href = "<%=basePath%>qm/queryProcess?parId="+parId
    }

    function goItemDetail(deaId) {
        let parId = $('#parId').val()
        let procId = $('#procId').val()
        window.location.href = "<%=basePath%>qm/partItemDetail?parId=" + parId + "&deaId=" + deaId + "&procId=" + procId
    }

    function getResultOptions(type) {
        let optionsTem = []
        $.ajax({
            type: "get",
            url: "<%=basePath%>api/qm/parts/getPartsOptions?type=" + type,
            dataType: "json",
            async: false,
            headers: {
                token: localStorage.getItem("token")
            },
            success: function (data) {
                if (data.code == 60200) {
                    optionsTem = data.data
                } else {
                    $.toptip('获取配置项失败', 'error');
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(errorThrown);
            }
        });
        return optionsTem
    }
</script>
</html>
